from django.db import models


class Aircraft(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    name = models.CharField(verbose_name='飞机名称', db_column='name', max_length=20)
    first_class_number = models.PositiveSmallIntegerField(verbose_name='头等舱数量', db_column='first_class_number',
                                                          help_text='请设置为偶数')
    economy_class = models.PositiveSmallIntegerField(verbose_name='经济舱数量', db_column='economy_class',
                                                     help_text='请设置为偶数')

    def __str__(self):
        return f'{self.name}'

    class Meta:
        db_table = 'aircraft'
        verbose_name_plural = '飞机管理'


class RouteInfo(models.Model):
    id = models.AutoField(db_column='id', primary_key=True)
    flight_name = models.ForeignKey(Aircraft, models.DO_NOTHING, verbose_name='飞机名称', db_column='flight_name', related_name='routeInfo_flight_name')
    from_place = models.CharField(verbose_name='航线起点', db_column='from_place', max_length=20)
    to_place = models.CharField(verbose_name='航线终点', db_column='to_place', max_length=20)
    start_time = models.DateTimeField(verbose_name='出发时间', db_column='start_time')
    end_time = models.DateTimeField(verbose_name='到达时间', db_column='end_time')
    first_class_price = models.FloatField(verbose_name='头等舱价格', db_column='first_class_price')
    economy_class_price = models.FloatField(verbose_name='经济舱价格', db_column='economy_class_price')

    def __str__(self):
        return f'{self.flight_name}' + f'--{self.from_place}' + f'--{self.to_place}'

    class Meta:
        db_table = 'route_info'
        verbose_name_plural = '航线管理'
